//index.js
//获取应用实例
const app = getApp()
// 引入域名
const host = require('../../config').host
Page({
  data: {
    haiguan: [],
    showModal:false,
    inputVal:"",
    host:host,
    scrollHeight: 0,
  },
  score: function (e){
    wx.navigateTo({
      url: `./score?id=${e.currentTarget.dataset.id}&article_type=${e.currentTarget.dataset.article_type}`
    })
  },
  toScore: function(e){
    wx.navigateTo({
      url: `../user/adminNewExpert?id=${e.currentTarget.dataset.id}`
    })
  },
  readfile: function (e){
    wx.navigateTo({
      url: `./readFile?id=${e.currentTarget.dataset.id}`
    })
  },
  inputTyping: function (e){
    // console.log(e)
    this.setData({
      inputVal: e.detail.value
    })
  },
  search: function (e){
    // console.log(this.data.inputVal)
    // var content = e.detail.value
    this.setData({
      pendingTabs: "",
      admin_expertes: ""
    })
    var that = this
    wx.request({
      url: host+'api/adminreview/search',
      data:{id:app.globalData.id,content:this.data.inputVal},
      success: function(res){
        that.setData({
          pendingTabs: res.data.works,
          admin_expertes: res.data.experts,
          lists: "display",
          showModal:true
        })
      },
      fail: function(data){
        // console.log(data)
      }
    })
  },
  listsDetail:function(e){
    wx.navigateTo({
      url: `./listsDetail?id=${e.currentTarget.dataset.id}&article_type=${e.currentTarget.dataset.article_type}`
    })
  },
  toFavorites: function(e) {
    console.log(e)
    var that = this
    var expert_id = e.currentTarget.dataset.id
    wx.request({
      url: host+'api/expert/search',
      data:{id:app.globalData.id,expert_id:expert_id,content:this.data.inputVal},
      success: function(res){
        that.setData({
          exportTabs: res.data
        })
      },
      fail: function(data){
        // console.log(data)
      }
    })
  },
  // changeData:function(){
  //   this.onLoad();//
  // },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  // onUnload: function () {
  //   var pages =getCurrentPages();//当前页面栈
  //   if (pages.length >1) {
  //       var beforePage = pages[pages.length- 2];//获取上一个页面实例对象
  //       beforePage.changeData();//触发父页面中的方法
  //   }
  // },
  onLoad: function () {
    if(this.data.inputVal != ""){
      this.search();
    }
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
